#include "btree.h"

void preOrder(BTreeNode *root) {
    if (root == NULL) {
        return;
    }

    std::cout << root->val << std::endl;
    preOrder(root->left);
    preOrder(root->right);
}

void inOrder(BTreeNode *root) {
    if (root == NULL) {
        return;
    }

    preOrder(root->left);
    std::cout << root->val << std::endl;
    preOrder(root->right);
}


void postOrder(BTreeNode *root) {
    if (root == NULL) {
        return;
    }

    preOrder(root->left);
    preOrder(root->right);
    std::cout << root->val << std::endl;
}

int main(int argc, char **argv){
    BTreeNode *node3_1 = new BTreeNode(4);
    BTreeNode *node3_2 = new BTreeNode(5);
    BTreeNode *node3_3 = new BTreeNode(6);
    BTreeNode *node3_4 = new BTreeNode(7);

    BTreeNode *node2_1 = new BTreeNode(2, node3_1, node3_2);
    BTreeNode *node2_2 = new BTreeNode(3, node3_3, node3_4);

    BTreeNode *root    = new BTreeNode(1, node2_1, node2_2);

    // 1. preOrder
    // preOrder(root);
    // inOrder(root);
    postOrder(root);


    delete node3_1;
    delete node3_2;
    delete node3_3;
    delete node3_4;
    delete node2_1;
    delete node2_2;
    delete root;
    return 0;
}